home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-12-02 | 3.6 KB | 163 lines | [TEXT/MMCC] |
- /*
- File: MathComponentCommon.c
-
- Contains: Math component routines.
-
- Written by: Gary Woodcock
-
- Copyright: © 1992 by Apple Computer, Inc.
-
- Change History (most recent first):
-
- */
-
- //-----------------------------------------------------------------------
- // Includes
-
- #include "MathComponent.h"
- #include "MathComponentCommon.h"
- #include "MathComponentPrivate.h"
- #include <OSUtils.h>
-
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult MathOpen (ComponentInstance self)
- {
-
- ComponentResult result = noErr;
- PrivateGlobals** globals;
- short count;
-
- // Can we open another instance?
- count = CountComponentInstances ((Component) self);
- if (count <= kMaxMathInstances)
- {
- // Did we get our storage?
- globals = (PrivateGlobals**) NewHandleClear (sizeof (PrivateGlobals));
- if (globals != nil)
- {
- // Keep a reference to self
- (*globals)->self = (Component) self;
-
- // Init private fields
- (*globals)->capturingComponentInstance = 0L;
- (*globals)->delegateComponent = 0L;
- (*globals)->delegateComponentInstance = 0L;
- // Set storage ref
- SetComponentInstanceStorage (self, (Handle) globals);
- }
- else // NewHandleClear failed
- {
- result = MemError();
- }
- }
- else // No more instances can be opened
- {
- result = kGenericError;
- }
- return (result);
- }
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult MathClose (Handle storage,
- ComponentInstance self)
- {
- ComponentResult result = noErr;
- PrivateGlobals** globals = (PrivateGlobals**) storage;
-
- // Do we have any clean up to do?
- if (globals != nil)
- {
- // Dispose globals
- DisposeHandle ((Handle) globals);
- globals = nil;
-
- }
- return (result);
- }
-
- //-----------------------------------------------------------------------
- pascal ComponentResult MathCanDo (short selector)
- {
- // Case on the request code
- switch (selector)
- {
- // Component Manager request codes
- case kComponentOpenSelect:
- case kComponentCloseSelect:
- case kComponentCanDoSelect:
- case kComponentVersionSelect:
- case kComponentTargetSelect:
-
- // Math component request codes
- case kDoDivideSelect:
- case kDoMultiplySelect:
- {
- return (true);
- }
- case kComponentRegisterSelect: // Register request not supported
- default: // Not a request code we recognize
- {
- return (false);
- }
- }
- }
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult MathVersion (void)
- {
- // Return the version info
-
- return (mathInterfaceRevision);
- }
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult MathTarget (Handle storage,
- ComponentInstance capturingComponent)
- {
- ComponentResult result = noErr;
- PrivateGlobals** globals = (PrivateGlobals**) storage;
-
- // Set reference to capturing component
- (*globals)->capturingComponentInstance = capturingComponent;
-
- return (result);
- }
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult MathDoDivide (short numerator,
- short denominator,
- short *quotient)
- {
- ComponentResult result = noErr;
- if (denominator != 0)
- {
- *quotient = numerator/denominator;
- }
- else // Divide by zero not allowed
- {
- *quotient = 0;
- result = kGenericError;
- }
- return (result);
- }
-
- //-----------------------------------------------------------------------
-
- pascal ComponentResult MathDoMultiply (short firstNum,
- short secondNum,
- short *multiplicationResult)
- {
- ComponentResult result = noErr;
- *multiplicationResult = firstNum * secondNum;
-
- return (result);
- }
-
- //-----------------------------------------------------------------------
-